﻿using Lottery.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Lottery
{
    /// <summary>
    /// ConfigWindows.xaml 的交互逻辑
    /// </summary>
    public partial class ConfigWindows : Window
    {
        public ConfigWindows()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("是否清除所有中奖者？", "清除中奖者", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
            if (result.Equals(MessageBoxResult.Yes))
            {
                WinnerData.Instances.clean();
                this.Close();
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                MyConfig.Instance.AppTitle = this.TextBox1.Text.Trim();
                MyConfig.Instance.MessageBar = this.TextBox2.Text.Trim();
                MyConfig.Instance.TimeClose = Convert.ToInt32(this.timeBar.Value);
                MyConfig.Instance.Save();
                MessageBoxResult result = MessageBox.Show("保存成功", "配置");
                this.Close();

            }
            catch
            {

            }
        }


        private void timeBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            try
            {
                this.timeShow.Content = Convert.ToInt32(this.timeBar.Value) + "秒";

            }
            catch
            {

            }

        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Escape)
            {
                this.Close();
            }
        }

        private void Window_Initialized(object sender, EventArgs e)
        {
            this.timeBar.Value = MyConfig.Instance.TimeClose;
            this.TextBox1.Text = MyConfig.Instance.AppTitle;
            this.TextBox2.Text = MyConfig.Instance.MessageBar;
        }
    }
}
